import { Component } from '@angular/core';
import { ModalService, ConfirmService, Pagination } from 'ng-tui';
import { InventoryService } from '../../services/inventory.service';
import { Inventory } from '../../interfaces/inventory.interfaces';
import { ApiData, SearchParams } from '../../../../cores/classes';
import { RequestService, GlobalService } from '../../../../cores/services';
@Component({
    template: `
    <ts-datepicker #datepickerThree="tsDatepicker" [(ngModel)]="inventory.beginOfPeriodDate" [color]="global.params.color"
    name="couponName"></ts-datepicker>
    <div class="modal-header">
    <h5 class="modal-title">新增库存</h5>
    <button (click)="close()" type="button" class="close">
        <span aria-hidden="true">&times;</span>
    </button>
</div>
<div class="modal-body">
    <div style="flex: 1 1 auto;padding: 1.25rem 0rem 1.25rem 0rem;">
        <div class="form-group row" style="display:flex;">
            <label class="col-sm-2 col-form-label label-required text-right" style="padding-right: 0px;">期初单号</label>
            <div class="col-sm-4">
                <input type="text" [(ngModel)]="inventory.beginOfPeriodOrderNumber" class="form-control">
            </div>
            <label class="col-sm-2 col-form-label label-required text-right" style="padding-right: 0px;">仓库名称</label>
            <div class="col-sm-4">
                <select [(ngModel)]="inventory.warehouseId" class="custom-select">
                <option value="" style="color: #b6b6b6" disabled selected selected="selected">请选择</option>
                <option *ngFor="let item of warehouse" [ngValue]="item.id">{{item.warehouseName}}</option>
            </select>
            </div>
        </div>

        <div class="form-group row" style="display:flex;">
            <label class="col-sm-2 col-form-label label-required text-right" style="padding-right: 0px;">商品品种数</label>
            <div class="col-sm-4">
              <input type="text" [(ngModel)]="inventory.goodsVarietiesNumber" class="form-control">
            </div>
            <label class="col-sm-2 col-form-label label-required text-right" style="padding-right: 0px;">商品总数量</label>
            <div class="col-sm-4">
               <input type="text" [(ngModel)]="inventory.goodsTotalNumber" class="form-control">
             </div>
        </div>
        <div class="form-group row" style="display:flex;">
            <label class="col-sm-2 col-form-label label-required text-right" style="padding-right: 0px;">商品总箱数</label>
            <div class="col-sm-4">
               <input type="text" [(ngModel)]="inventory.goodsTotalBoxesNumber" class="form-control">
            </div>
            <label class="col-sm-2 col-form-label label-required text-right" style="padding-right: 0px;">商品总金额</label>
            <div class="col-sm-4">
               <input type="text" [(ngModel)]="inventory.goodsTotalMoney" class="form-control">
            </div>
        </div>
        <div class="form-group row">
            <label class="col-sm-2 col-form-label label-required text-right" style="padding-right: 0px;">期初日期</label>
        <div class="col-sm-4">
        <input tsToggle [target]="datepickerThree" [bind]="datepickerThree"
        [value]="inventory.beginOfPeriodDate "placeholder="请选择日期" type="text"  class="form-control ht bg-white pointer required" >
        </div>
        </div>
    </div>
    <div class="modal-footer">
        <button tsBtn (click)="modal.dismiss()">取消</button>
        <button tsBtn loading color="success" (submit)="confirmSave($event)">保存</button>
    </div>`,
})
export class ModalCostComponent {
    // name="couponName"[(ngModel)]="voucher.couponName"
    // content = '...';
    inventory: Inventory = { id: 0, beginOfPeriodDate: '' };
    changg: number;
    loading = false;
    search = new SearchParams({ status: '' });
    pagination = new Pagination();
    warehouse = new Array<Inventory>();
    nowD = new Date();



    constructor(
        private modal: ModalService,
        private inventoryService: InventoryService,
        private confirm: ConfirmService,
        public global: GlobalService,
    ) {
        this.departmentLista();
    }


    close() {
        this.modal.dismiss();
    }

    confirmSave(btn: any) {
        (this.inventory.id > 0 ? this.inventoryService.updateinven(this.inventory) : this.inventoryService.insertinven(this.inventory))
            .subscribe({
                next: () => this.modal.close(),
                complete: () => btn.dismiss()
            });
    }
    // testa() {
    //     this.voucherService.insertCompany(this.voucher).subscribe({
    //         next: res => {
    //             this.confirm.success('添加成功', `'${this.voucher.couponName}`);
    //             this.close();
    //             this.loadDatas();

    //         }
    //     });
    // }

    /**
       * 仓库列表
       */
    departmentLista() {
        this.inventoryService.addhouse()
            .subscribe({
                next: res => {
                    this.warehouse = res.datas;
                },
            });
    }
}

